home *** CD-ROM | disk | FTP | other *** search
/ 2,000 Greater & Lesser Mysteries / 2,000 Greater and Lesser Mysteries.iso / computer / virus / mys00475.txt < prev    next >
Encoding:
Text File  |  1994-06-10  |  18.2 KB  |  298 lines

  1. Portal-Rmail-To: garyt@cup.portal.com
  2. Received: by portal.com (3.2/Portal 8)
  3.     id AA13156; Wed, 26 Apr 89 01:38:23 PDT
  4. Received: from Sun.COM (arpa-dev) by sun.Sun.COM (4.0/SMI-4.0)
  5.     id AA18522; Tue, 25 Apr 89 23:07:59 PDT
  6. Received: from sun by Sun.COM (4.1/SMI-4.0)
  7.     id AB12617; Tue, 25 Apr 89 23:07:12 PDT
  8. Message-Id: <8904260607.AB12617@Sun.COM>
  9. Received: from LEHIIBM1.BITNET by IBM1.CC.Lehigh.Edu (IBM VM SMTP R1.2) with BSMTP id 5945; Wed, 26 Apr 89 02:02:46 EDT
  10. Received: by LEHIIBM1 (Mailer R2.03A) id 5720; Wed, 26 Apr 89 02:02:42 EDT
  11. Date:         Wed, 26 Apr 89 02:02:41 EDT
  12. From: Revised List Processor (1.5o) <LISTSERV@IBM1.CC.Lehigh.Edu>
  13. Subject:      File: "V101 2" being sent to you
  14. To: "Gary F. Tom" <sun!portal!cup.portal.com!garyt>
  15.  
  16. Subject: Virus 101 - Chapter 2
  17. From: woodside@ttidca.TTI.COM (George Woodside)
  18. Newsgroups: comp.sys.atari.st,comp.sys.apple,comp.sys.mac,comp.sys.ibm.pc
  19. Date: 6 Mar 89 14:00:21 GMT
  20. Reply-To: woodside@ttidcb.tti.com (George Woodside)
  21. Organization: Citicorp/TTI, Santa Monica
  22.  
  23. In response to a lot of the mail I've received:
  24.  
  25. 1) You haven't missed the "rest of the chapters". I'm posting them as I
  26.    get them written.
  27.  
  28. 2) You may not agree with me. I tried to set down the definitions and
  29.    terms as I would be using them, for the benefit of those who weren't
  30.    familiar with them. This whole area is rather vague, and most of us
  31.    in the trenches and making up the rules, as we learn the game.
  32.  
  33. When we left our virus at the end of Chapter 1, it had managed to get itself
  34. installed in our system by being present on the boot sector of a disk in the
  35. machine at cold start or reset.
  36.  
  37. Another way a virus may be installed is via a trojan horse program. Trojan
  38. horses come in many flavors. Some disguise themselves as programs which
  39. provide some useful function or service, while secretly doing something
  40. else. The something else may be installing a virus, sabotaging some part of
  41. a disk, setting up hooks to steal passwords on time sharing systems, or
  42. whatever else you can imagine. In the event of the virus installer, the
  43. trojan horse has a bit more flexibility than a typical boot sector virus,
  44. simply because it doesn't have to fit itself into a relatively small space.
  45. Since it is hiding in a larger program, it can be whatever size is necessary
  46. to accomplish the task.
  47.  
  48. A typical boot sector contains information about the layout of the disk it
  49. resides upon. This block of data requires 26 bytes. The first three bytes of
  50. the boot sector are left available for an assembly language "jump" command,
  51. to allow the execution of the code to skip over the boot sector's data
  52. block. And, the boot sector must add up to the proper magic number to have
  53. executable status. That will require another two bytes, since the checksum
  54. is a 16 bit value. So, 31 bytes are allocated. Since (at least in the 68000
  55. family) machine instructions are always 16 bits and must begin on an even
  56. address, 32 of the 512 bytes in the boot sector are not available to any
  57. executable program. So, there are 480 bytes available for the executable
  58. code. Machine instructions vary in length, depending upon what they do, and
  59. how much additional information is required. In the 68000, instruction
  60. lengths vary from one to five words, but a reasonable average instruction
  61. length for a program is just over two words. That translates the 480 bytes
  62. to 120 instructions.
  63.  
  64. The virus must contain the code to install itself, reserve the memory it
  65. occupies to keep subsequent programs from over-writing it, spread itself to
  66. other disks, and whatever it really intends to do once it decides it is time
  67. to act. That's quite a bit of code to fit into 120 instructions, unless it
  68. extends itself by loading some other part of the disk, or a file.
  69.  
  70. Files are pretty much out of the question. Most computer users would notice
  71. if some file they didn't recognize started popping up on a lot of their
  72. disks. There are attributes settable in a disk directory which can be used
  73. to tell the operating system that certain files are "Hidden" or "System"
  74. files. If the file had the proper status bits set, it could prevent itself
  75. from appearing in normal disk directory displays. There are, however, more
  76. flexible disk directory listing programs which will display the entries for
  77. these files, as well as normal files. There is also the problem of the space
  78. the hidden file occupies, as well as the directory entry. The space
  79. available on the disk will be less than it should be, since the hidden file
  80. is present. These symptoms would not escape detection for long.
  81.  
  82. A more effective method is the use of specific disk sectors. The standard
  83. disk layout covered in the preceeding chapter mentioned such things as File
  84. Allocation Tables, and disk directory space. In a standard format Atari
  85. disk, for example, each FAT is 5 sectors long, and the directory is 7
  86. sectors long. That is more than enough FAT space to accomodate the entire
  87. disk. A virus in need of more space than 480 bytes might write the remainder
  88. of itself in the last sector of the FAT (I have one that does this). It
  89. might also write itself in the last sector of the directory, taking
  90. advantage of a quirk in the operating system.
  91.  
  92. When a disk is formatted, all data sectors are normally filled with a
  93. pre-defined value, E5 (hexadecimal). The directory and FAT space is usually
  94. set to 00. When a directory entry is made active, the file name is written
  95. in the directory, along with some other required information. When a file is
  96. deleted, the first byte of the directory entry is set to E5. That makes the
  97. entry available again. This is a carry over from the early days of floppy
  98. disks, when where the directory would exist on a disk was not as well
  99. defined. The directory entries had to appear as empty on a freshly formatted
  100. disk, so E5 was used as a deleted entry mark. That way, no matter where the
  101. directory was, a freshly formatted disk would always appear as empty. Now,
  102. since disk formats are more flexible, the directory is located by
  103. parameters, and normally the entire directory space is zeroed at formatting
  104. time. Since an active entry will have some legitimate ASCII character in the
  105. beginning of the file name, and a deleted entry will have E5 in the first
  106. byte, it is generally assumed that encountering a directory entry with a
  107. value of 00 in the first byte indicates that the entry has never been used.
  108. Since directory entries are used (and deleted ones re-used) on a first-found
  109. basis, finding one with 00 means that not only has it not been used, but
  110. none of the ones following it will have been used either. Consequently, most
  111. software stops looking at the directory entries when a 00 entry pops up. If
  112. there are several more sectors available, there may be something hiding out
  113. there, beyond the last used entry. While this method of hiding is not
  114. foolproof, the typical virus is not concerned about being bulletproof in all
  115. cases. It just has to survive long enough to reproduce itself, and it has
  116. half the battle won. As long as it keeps spreading, sooner or later it will
  117. survive long enough to do the task it is designed to do, then it wins both
  118. halves of the battle.
  119.  
  120. There are other ways for the virus to get additional disk space. Typically,
  121. floppy disks are not used up a sector at a time, but rather in groups of
  122. sectors. Each group of sectors is referred to as a data "cluster". The
  123. number of sectors in a cluster is variable, and is one of the parameters
  124. stored in the boot sector. If the number of data sectors on the entire disk,
  125. minus the boot sector, FATs, and directory, is not an exact multiple of the
  126. number of sectors in a data cluster, the remaining sectors will never be
  127. used by the opearting system. A clever virus can find them and hide there.
  128. The inconvenience of this is that the unused sectors would normally be at
  129. the end of the last track of the disk, causing long (and noticeable) disk
  130. seeks to load or spread the virus.
  131.  
  132. There is a parameter in the boot sector designed to permit the disk to have
  133. sectors reserved for any purpose, and not accessed as part of the normal
  134. data area. A virus could also use this method to extend itself, but it, too,
  135. has shortcomings. Using this feature requires the parameter to be set when
  136. the disk has absolutely no data on it. Reserving sectors causes the start of
  137. the data area to be moved further into the disk. While the data area would
  138. be moved, the data already on the disk would not. Consequently, altering the
  139. reserved sectors parameter would make all files on the disk garbage. (They
  140. could be returned to proper status by restoring the original value to the
  141. reserved sectors parameter, providing no disk write had occurred.) There
  142. would also be the problem of the disk's free space being less that it
  143. should.
  144.  
  145. Consequently, if a virus needs extra space, using prescribed system features
  146. or hidden files is not a good choice, since it is too easily detected. The
  147. approach used so far is to hide in sectors unlikely to be used, and hope to
  148. spread before they get clobbered (and it works).
  149.  
  150. OK, so now the virus has managed to get onto a disk in your library, and
  151. then get itself booted into your system at startup or reset. It may have
  152. been on a disk you received from someone, and booted with, or it may even
  153. have been installed by a trojan horse, but it is in your system. How does it
  154. spread?
  155.  
  156. There are ways, and then there ways.....
  157.  
  158. The most common method is through the vector reserved for floppy disk read
  159. and write functions. As we saw in Chapter 1, floppy disks get changed (some
  160. surprise, eh?). One disk is removed, and another is inserted. When that
  161. happens, the operating system is notified by the physical act of changing
  162. the disk that the event has occurred. How that event is detected will vary
  163. with different disk drives, but there are two common methods. One is the
  164. disk drive latch. Some hardware reports the transition of the latch on the
  165. floppy disk drive's door. When the locking lever is moved, a signal is sent
  166. to the disk controller card, indicating that the disk door has been opened.
  167. (Door is a carry over term from older drive mechanisms which had fully
  168. closing doors over the disk drive slot.) The operating system makes note of
  169. the fact that a disk change may have occurred.
  170.  
  171. The other method is the write protect notch. On both 5 1/4 and 3 1/2 inch
  172. disks, the write protect notch tab is located in a position which makes it
  173. impossible to fully remove and install a disk without having the write
  174. protect detection mechanism be fully obstructed at some point, and fully
  175. unobstructed at some point. The detection mechanism may be a physical sense
  176. switch, or an optical sensor. Either way, as the body of the disk is removed
  177. from the drive, it will be blocked. Then, when the disk is out, the sense
  178. area is open. So, the drive will report transitions on the status line. The
  179. operating system notes the change, and sets the necessary flags to indicate
  180. that the disk may not be the same one that was there a little while ago. It
  181. may also be, if the same disk was re-inserted, but that's not important. The
  182. fact that it may have changed is very important. Attempting to read or write
  183. to the disk, without first noting the characteristics of it, could be very
  184. destructive.
  185.  
  186. When the next access of the (possibly) changed disk occurs, the operating
  187. system will read the boot sector. In MS-DOS systems, I believe that the
  188. operating system assumes that if there is a possiblity that the disk has
  189. changed, it assumes that it has, dumps all information relative to the old
  190. disk, and starts fresh. In the Atari, the operating attempts to be a bit
  191. smarter. The boot sector contains a serial number which is supposed to be
  192. unique across all disks. This serial number is 12 bits long, and is assigned
  193. when the disk is formatted. If there is a possibility that the disk has
  194. changed, the operating system reads the serial number. If the serial number
  195. is different than before, the disk has changed, all old data is wiped out,
  196. and the new serial number is noted. If the serial number is the same, the
  197. disk has presumably not changed, and the data in the operating system's
  198. internal buffers is assumed to be valid. This leads to thoroughly trashed
  199. disks if two disks have identical serial numbers, and are used
  200. consecutively.
  201.  
  202. In any event, when a possible disk change has occurred, the boot sector is
  203. always read to determine the characteristics of the new disk. The operating
  204. system uses the floppy disk read function to access the first sector on the
  205. disk. As previously noted, this disk read function is pointed to by a
  206. vector. If the vector has been altered to point to a virus, the plot
  207. thickens...
  208.  
  209. We will assume a typical floppy disk boot sector virus for a while, and see
  210. exactly what happens. The virus first checks the number of the drive being
  211. accessed. If it is not a floppy disk, it passes the call on to the address
  212. it found in the vector. No harm done.
  213.  
  214. If the call is to a floppy disk, most viruses check the side, track, and
  215. sector of the call to see if it is the boot sector. If it isn't, it passes
  216. the call on, and again, no harm done. Why? Performance. Not that the virus
  217. cares about good disk performance, mind you. What it cares about is being
  218. noticed. If it was busy snagging all the disk calls, and checking the boot
  219. sector all the time, there would be an incredible increase in disk head
  220. seeking, and a very noticeable drop in performance of the system. Anyone
  221. with at least half a brain (witch inkluds sum smarter komputer pepel) would
  222. notice that, and would become inquisitive about what was happenning. The
  223. virus would have given itself away. No self-respecting virus would want to
  224. be detected before it got a chance to spread, and possibly wreak a bit of
  225. havoc, so it remains inactive until it can accomplish its task unnoticed.
  226.  
  227. When the read call is to the boot sector, the virus goes into action. The
  228. data is read into a buffer, as designated by the host operating system's
  229. call, exactly as expected. Normally, the disk read function would return to
  230. the operating system at this point, but the virus doesn't. Depending upon
  231. the sophistication of the virus, several things may happen. Some viruses
  232. will first check the image of the boot sector in the buffer, to see if they
  233. are already on the disk. If they find the disk already has the virus, the
  234. go back to sleep (pleased, we assume!). Some even check revision levels in
  235. the virus image, and replace themselves if the disk had a more recent
  236. version of themselves!
  237.  
  238. If the image from the boot sector is not the virus, some will check to see
  239. if the image was of an executable boot. If it was, the virus does not alter
  240. it. Doing so would make a self-booting disk fail forever after, and would
  241. probably lead to the detection of the virus. Other viruses, not as
  242. sophisticated, will not execute this test, and may be spotted more readily.
  243.  
  244. Now, assuming that the boot sector is not executable, or that it is but this
  245. virus is too dumb to leave it alone, it's time for the virus to spread.
  246. There is a copy of the boot sector from the original virus disk in a
  247. reserved memory area, from the original boot up process. The executing copy
  248. of the virus knows where that is, since it reserved the memory for itself
  249. and the image at the same time. The characteristics of the disk the virus
  250. came from may not be the same as the disk in the machine now.  Depending
  251. upon the operating system's standards, the virus will either copy the disk
  252. parameter information from the current disk into its own image buffer, or
  253. copy its image into the current disk's buffer, leaving the disk's parameters
  254. unchanged. Either way, the result is a copy of the current disk's
  255. parameters, combined with the executable image of the virus.  Now, the
  256. executable status checksum must be computed, and added to the buffer. This
  257. may be accomplished by a routine in the virus, or by an operating system
  258. call. If the virus is on an Atari, it might be careful enough to insure that
  259. the serial number on the new disk remains the same.  Failing to do so would
  260. lead to all disks with the virus having the same serial number. That would
  261. lead to disks being accidently altered (due to the serial number test), and
  262. the virus would probably be detected too soon.
  263.  
  264. When the new checksum is completed, the updated boot sector is re-written to
  265. the disk. All this occurs in much less than the time required for the floppy
  266. disk to make a single revolution, so the boot sector is re-written on the
  267. next spin. Since the rotation speed of the disk is either 300 or 360 rpms,
  268. the total time lost is less than 1/5 of one second. Nearly impossible for
  269. anyone to notice, when combined with the time required for the drive to load
  270. the head, seek to track zero, read the sector, etc.
  271.  
  272. The only potential problem here is one of the virus' intended victim's
  273. primary levels of defense: the write protect feature. Despite rumors to the
  274. contrary, I have not seen a virus capable of writing to a write protected
  275. disk. The hardware in the disk drive will not write if the write protect
  276. status is set. It reports an error to the operating system. The virus can
  277. not override this protection, but it must be wary of it. Older viruses were
  278. sometimes spotted when a system error occurred, reporting that an attempt
  279. was being made to write to a disk which was write protected. If the function
  280. being performed (listing a directory, for example) should not be writing to
  281. the disk, there was reason to become suspect. Most viruses now are more
  282. sophisticated. They take over the error vector before attempting the write,
  283. and restore it afterwards. That way, if the attempt to spread themselves to
  284. the new disk fails, the error never gets reported. While the user doesn't
  285. know that the attempt was ever made, the disk also doesn't get infected.
  286.  
  287. Many viruses run counters. Some count the number of already infected disks
  288. they have seen, while others count the number of disks they infect. Either
  289. way, the counting viruses have some threshold they are attempting to reach.
  290. When they reach that number, they (presumably) consider themselves
  291. thoroughly spread, and it is now time to start their third act.
  292.  
  293. End of Chapter 2.
  294. --
  295.  
  296. *George R. Woodside - Citicorp/TTI - Santa Monica, CA
  297. *Path:       ..!{philabs|csun|psivax}!ttidca!woodside
  298.